WEBVTT

00:01.080 --> 00:03.000
Hello and welcome back to our costs.

00:03.000 --> 00:07.830
Soon the last session we learned that India raised containers of homogeneous data.

00:08.340 --> 00:10.800
So in particular for numerical data.

00:10.800 --> 00:15.990
And this allows us to make fast element Weiss and vector rise operations.

00:16.020 --> 00:22.920
So far we have only seen one dimensional arrays are only one sequence of elements and in linear algebra.

00:22.950 --> 00:24.330
You would call it a vector.

00:24.780 --> 00:31.200
And this is only a special case of India race and the general case is a multi-dimensional array.

00:31.200 --> 00:33.010
And in the case of two dimensions.

00:33.170 --> 00:39.720
Yeah you and Linnea argue probably would call it a matrix and the matrix S rows and columns and the

00:39.720 --> 00:41.520
amount of elements in the row.

00:41.520 --> 00:48.450
So if you count the number of elements from left to right is the size of a row and the amount of elements

00:48.450 --> 00:49.080
in a column.

00:49.080 --> 00:55.770
So we account the elements from top to the bottom is the size of the column and the size of each of

00:55.770 --> 00:57.160
those dimensions.

00:57.210 --> 01:01.920
Give us the shape so for example we have three rows and four columns.

01:01.920 --> 01:06.450
But now let's stop coding so we important umpires and P as always.

01:06.540 --> 01:13.830
Then we create a num pi array from one to twelve including and we can check the type.

01:13.890 --> 01:20.100
So should be an end the array and then we can check the shape of our end the array.

01:20.100 --> 01:27.360
So by calling the attribute shape and here you can see it's a one dimensional array so we have only

01:27.360 --> 01:28.440
one dimension here.

01:28.440 --> 01:31.120
If we had to ask me I mentioned c what if.

01:31.370 --> 01:38.250
Yeah two or three numbers here it's a one dimensional array containing of twelve elements in linear

01:38.280 --> 01:38.870
algebra.

01:38.880 --> 01:41.560
You would call it a vector of its elements.

01:41.640 --> 01:47.790
And what we got now can do we can reshape our ending array with the method.

01:47.820 --> 01:54.240
Dot reshape and then we can determine how the shape should look like the first position determines the

01:54.240 --> 01:58.110
amount of rows and the second position determines the amount of columns.

01:58.150 --> 02:04.440
Yeah we want transform our one dimensional array with both elements into an array with two rows and

02:04.500 --> 02:06.780
each row has six columns.

02:06.780 --> 02:16.670
So let's run the cell and let's have a look at a funny you can see Python returns us a two dimensional

02:16.670 --> 02:17.270
array.

02:17.330 --> 02:24.440
So we have here an outer array and this is containing two arrays so two rows here in this example.

02:24.470 --> 02:33.030
So we have the first row and the second row and each row has six columns.

02:33.090 --> 02:37.350
And we can also check now on the shape of our new two dimensional array.

02:38.760 --> 02:45.690
And it's no surprise two and six so two rows six columns of course we can also reshape our array to

02:45.690 --> 02:49.920
the shape six rows and two columns.

02:49.920 --> 02:55.110
Also here with the reshape method.

02:55.240 --> 03:00.250
So now you can see we get six rows and each row containing two elements.

03:00.250 --> 03:11.560
So we have six rows and two columns and let's also check the shape it's six rows and two columns an

03:11.600 --> 03:18.420
element y's operations or vector US operations still work in the same manner as with only a one dimensional

03:18.420 --> 03:18.680
array.

03:18.690 --> 03:20.180
So that's no problem.

03:20.190 --> 03:26.700
So if we add hundreds to a we at 100 to each element of our array.

03:26.790 --> 03:31.950
So before we add Tier 1 2 in the first row now we have 101 and 102 and so on.

03:31.950 --> 03:35.870
So now let's remind that we have in total twelve elements in our array.

03:36.000 --> 03:42.200
And she tried to reshape our array let's say into regrowth and five columns.

03:42.230 --> 03:46.110
So that would mean 15 elements.

03:46.110 --> 03:52.180
This does not work and pass and tests cannot reshape array of size twelve and to shape 3 5.

03:52.230 --> 03:58.490
And we are not limited to two dimensions so we can increase the amount of dimensions to let's say 3.

03:58.500 --> 04:05.280
So we can say okay we want to reshape the end the array and create a three dimensional array.

04:05.460 --> 04:07.800
So the first dimension is the size of two.

04:07.800 --> 04:11.970
The second is the size of two and the third dimension has to the size of three.

04:12.390 --> 04:17.370
So it's kind of a cube.

04:17.430 --> 04:23.190
So now you can see here this is the first element of the first dimension and this is the second element

04:23.190 --> 04:29.970
of the first dimension so the first dimension contains two times the matrix consisting of two rows and

04:29.970 --> 04:30.780
three columns.

04:30.990 --> 04:33.720
So let's check the shape of a.

04:34.710 --> 04:40.560
And we get the shape as a three dimensional with the size 2 2 and 3.

04:40.560 --> 04:48.300
So now let's assume we want to create a two dimensional array containing of the numbers 1 to 100 including

04:48.300 --> 04:51.150
in the shape 25 rows and 4 columns.

04:51.150 --> 04:53.610
We can do that in our 1 line of code.

04:54.030 --> 05:02.140
So first of all we create a one dimensional array consisting of the numbers 1 2 100 and then we reshape

05:02.140 --> 05:06.210
the array and get 25 rows and 4 columns.

05:06.250 --> 05:10.720
So let's see what we get.

05:10.730 --> 05:20.710
So now we have field twenty five rows and four columns and our elements and immigrated from 1 to 100.

05:21.010 --> 05:21.390
All right.

05:21.400 --> 05:26.800
So this was the introduction to multi-dimensional arrays and they are and the next session you will

05:26.800 --> 05:30.480
have a look how to index and slice multi-dimensional arrays.

05:30.640 --> 05:33.370
So hope you are it and see you in the next session by.
